﻿using BLL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Com.Qkds.Erp.WebUi
{
    public partial class roleEdit : System.Web.UI.Page
    {
        public int pid
        {
            get
            {
                return int.Parse(ViewState["pid"].ToString());
            }
            set
            {
                ViewState["pid"] = value;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                pid = 0;
                string tablename = "Qx";
                this.ddlQx.DataSource = new roleBLL().Select(tablename);
                this.ddlQx.DataValueField = "ID";
                this.ddlQx.DataTextField = "Name";
                this.ddlQx.DataBind();
                if (Request["id"] != null)
                {
                    string TableName = "role";
                    pid = int.Parse(Request["id"].ToString());
                    roleModel model = new roleBLL().GetModelByID(TableName, pid);
                    this.txtName.Value = model.roleName;
                    this.ddlQx.SelectedValue = model.Qx;

                }

            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            roleModel model = new roleModel()
            {
                roleName = this.txtName.Value,
                Qx  = this.ddlQx.SelectedValue,
             

            };
            roleBLL bll = new roleBLL();
            if (pid > 0)
            {
                bll.Gai(model, pid);
                
            }
            else
            {
                bll.Add(model);

               
            }
            Response.Redirect("role.aspx");
        }
    }
}